class Api::V1::SessionsController < Api::V1::BaseController
	skip_before_filter :signed_in_user, :only => [:create]

	def new
	end

	def create
		user = User.find_by(email: params[:session][:email].downcase)

	    return render :status => 401, 
		    			:json => { 
	    					:status_code => 401, 
    						:message => "Wrong username or password!",
    						:content => ""
						} unless user

		if user.authenticate(params[:session][:password])
	  		 sign_in user
	  		 render :status => 201,
					:json => { 	
						:status_code => 201,
						:message => "You have signed in successfully!",
						:content => session[:remember_token]
					}

		else
			render :status => 401,
					:json => { 	
						:status_code => 401,
						:message => "Wrong username or password!",
						:content => ""
					}
		end
	end

	def destroy
		sign_out
	end
end
